package com.ruoyi.common.enums.wecom;

import cn.hutool.core.util.ObjectUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

@Getter
@AllArgsConstructor
public enum WecomMsgCallBackEventEnum {
    CHANGE_EXTERNAL_CONTACT("change_external_contact", "企业客户变更事件"),
    CHANGE_EXTERNAL_CHAT("change_external_chat", "企业客户群变更事件"),
    CHANGE_EXTERNAL_TAG("change_external_tag", "企业客户标签变更事件"),
    MSG_AUDIT_NOTIFY("msgaudit_notify", "产生会话回调事件"),
    SUBSCRIBE("subscribe", "关注"),
    UNSUBSCRIBE("unsubscribe", "取消关注"),
    ENTER_AGENT("enter_agent", "进入应用"),
    LOCATION("LOCATION", "上报地理位置"),
    BATCH_JOB_RESULT("batch_job_result", "异步任务完成事件推送"),

    ;

    private final String code;
    private final String desc;

    private static final Map<String, WecomMsgCallBackEventEnum> ENUM_MAP;

    static {
        WecomMsgCallBackEventEnum[] values = values();
        Map<String, WecomMsgCallBackEventEnum> enToCn = new HashMap<>(values.length);
        for (WecomMsgCallBackEventEnum value : values) {
            enToCn.put(value.getCode(), value);
        }
        ENUM_MAP = Collections.unmodifiableMap(enToCn);
    }

    /**
     * 根据类型查找枚举
     */
    public static WecomMsgCallBackEventEnum getEnumByType(String type) {
        WecomMsgCallBackEventEnum wecomMsgCallBackEventEnum = ENUM_MAP.get(type);
        if (ObjectUtil.isEmpty(wecomMsgCallBackEventEnum)) {
            throw new RuntimeException("类型有误");
        }
        return wecomMsgCallBackEventEnum;
    }

}
